package com.sun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.entity.Log;
import com.sun.entity.User;
import com.sun.mapper.UserMapper;
import com.sun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Project: hospitalDrugInformationManagement
 * @Author: 86178
 * @Date: 2023/2/7 10:29
 * @FileName: UserServiceImp
 * @Description: ""
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserByAccount(String account) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getAccount, account);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public User getUserByTel(String phone) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getTel, phone);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public String selcetUserName(Long id) {
        return userMapper.selcetUserName(id);
    }

    @Override
    public Log userToLoginLog(User userBean, Log loginLog) {
        loginLog
                .setTel(userBean.getTel())
                .setUserId(userBean.getId())
                .setAccount(userBean.getAccount())
                .setUserName(userBean.getNickName());
        return loginLog;
    }
}
